<template>
    <div id="user-edit">
        <Form ref="formValidate" :label-width="100" :model="parms" :rules="ruleValidate" label-position="right">
            <FormItem label="状态:" prop="statuz">
                <i-switch
                    v-model="parms.statuz"
                    :false-value="0"
                    :true-value="1"
                >
                    <span slot="0">On</span>
                    <span slot="1">Off</span>
                </i-switch>
            </FormItem>
            <FormItem label="新闻标题:" prop="title">
                <Input v-model="parms.title" placeholder="请输入标题"/>
            </FormItem>
            <FormItem label="副标题:" prop="deputyTitle">
                <Input v-model="parms.deputyTitle" placeholder="请输入副标题"/>
            </FormItem>
            <FormItem label="类型:" prop="category">
                <Input v-model="parms.category" placeholder="请输入类型"/>
            </FormItem>
            <FormItem label="新闻内容:" prop="content">
                <Input type="textarea" v-model="parms.content" placeholder="请输入新闻内容"/>
            </FormItem>
        </Form>
        <div style="text-align: center">
            <Button type="primary" @click="saveAdmins">保存</Button>
        </div>
    </div>
</template>

<script>
import {deepCopy} from "view-design/src/utils/assist";
import {extend} from "@/libs/tools";

export default {
    name: "user-edit",
    props: ['selectItem'],
    data() {
        return {
            parms: {
                id: '',
                title: '',
                content: '',
                statuz: 1,
                createTime: '',
                deputyTitle: ''
            },
            enterpriseList: [],
            ruleValidate: {
                title: [{required: true, message: '请输入账号', trigger: 'blur'}],
                content: [{required: true, message: '请输入姓名', trigger: 'blur'}],
            }
        };
    },
    mounted() {
        this.parms = extend(this.parms, this.selectItem)
    },
    methods: {
        //添加用户
        saveAdmins() {
            this.$refs.formValidate.validate(es => {
                if (!es) return
                let parms = deepCopy(this.parms);
                if (Object.keys(this.selectItem).length > 0) {
                    this.$emit('edit', parms)
                } else {
                    this.$emit('add', parms)
                }
            })
        }
    }
};
</script>
<style scoped>

</style>
